<?php
/**
 * 结账用户Model
 * @author solar
 */
class CheckoutUserModel extends BaseModel 
{
	public static $name='checkout_user';
	public static $primary='cu_id';
	
	public function __construct() {
		parent::__construct(CoreFactory::db(),self::$name,self::$primary);
	}
	
	/**
	 * 账单的用户数
	 * @author solar
	 * @param int $c_id
	 * @return int
	 */
	public function count($c_id) {
		return $this->getCount(array('c_id'=>$c_id));
	}
	
	/**
	 * 获取账单下面的用户支出消费列表
	 * @author solar
	 * @param int $c_id
	 * @return array
	 */
	public function listByCheckout($c_id) {
		return $this->db->fetchAllKey('SELECT * FROM `checkout_user` WHERE c_id='.$c_id,'u_id');
	}
	
	/**
	 * 创建
	 * @author solar
	 * @param int $c_id
	 * @param int $u_id
	 * @param float $cu_person_pay
	 * @param float $cu_person_spend
	 */
	public function create($c_id,$u_id,$cu_person_pay,$cu_person_spend,$cu_balance) {
		$row['c_id']=$c_id;
		$row['u_id']=$u_id;
		$row['cu_person_pay']=$cu_person_pay;
		$row['cu_person_spend']=$cu_person_spend;
		$row['cu_balance']=$cu_balance;
		return $this->insert($row);
	}
	
	/**
	 * 通过账单ID和用户ID获取记录
	 * @author solar
	 * @param int $user_id
	 * @param int $checkout_id
	 * @return boolean
	 */
	public function getCheckoutUser($user_id,$checkout_id) {
		return $this->getByField(array('c_id'=>$checkout_id,'u_id'=>$user_id));
	}
}

?>